<template>
	<view class="content">
		<view class="top">
			<view class="navtitle" :style="{ marginTop: data.rect }">我的</view>
			<view class="user">
				<image class="head l" :src="data.user.avatarUrl || '../../static/head.png'"></image>
				<view class="name l">
					<view>{{ data.user.name || '微信用户' }}</view>
					<view class="hy">会员ID：{{ data.user.mchMemberNo }}</view>
				</view>
			</view>
			<view class="manager">
				<image class="logo" :src="data.mch.logo"></image>
				<view class="shopinfo">
					<view class="title">{{ data.mch.title }}</view>
					<view class="vip">加入会员享好礼</view>
				</view>
				<view class="btn" @click="tovip">完善会员信息 ></view>
			</view>
		</view>

		<view class="jy">
			<view class="jy_item">
				<view class="l">
					<view class="jy_points">{{ data.user.points }}</view>
					<view class="jy_name">积分</view>
				</view>
				<image src="../../static/jf.png" class="jy_img r" mode="" />
			</view>
			<view class="jy_item">
				<view class="jy_num l">
					<view class="jy_points">暂未开放</view>
					<view class="jy_name">优惠卷</view>
				</view>
				<image src="../../static/yh.png" class="jy_img r" mode="" />
			</view>
		</view>
		<view class="ceil" v-if="data.token">
			<view class="ceil_title">商户服务</view>
			<view class="ceil_list">
				<view class="ceil_item" v-for="(item, index) in mop" :key="index" @click="jump(item.url)">
					<view v-if="item.enable">
						<image class="ceil_img" :src="item.img" mode="" />
						<view class="ceil_name">{{ item.title }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="ceil">
			<view class="ceil_title">用户服务</view>
			<view class="ceil_list">
				<view class="ceil_item" v-for="(item, index) in store" :key="index" @click="jump(item.url)">
					<image class="ceil_img" :src="item.img" mode="" />
					<view class="ceil_name">{{ item.title }}</view>
				</view>
			</view>
		</view>
		<button class="shop" @click="shop" v-if="data.token">退出商家</button>
	</view>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { get, err, set } from '@/utils/uniapi';
import { jump, tovip } from './my';
import { api } from '@/api/store_api';
const mop = ref([
	{ title: '会员列表', img: '../../static/vip.png', url: '/dj/vip/vip', enable: false },
	{ title: '商品分类', img: '../../static/goodtype.png', url: '/dj/type/type', enable: false },
	{ title: '商品列表', img: '../../static/good.png', url: '/dj/goods/goods', enable: false },
	{ title: '消费账单', img: '../../static/bill.png', url: '/dj/bill/bill', enable: false },
	{ title: '餐桌列表', img: '../../static/board.png', url: '/dj/board/board', enable: false },
	{ title: '查看营收', img: '../../static/skdp.png', url: '/dj/skdp/skdp', enable: false },
	{ title: '充值活动', img: '../../static/pay.png', url: '/dj/payhd/payhd', enable: false },
	{ title: '会员积分变更', img: '../../static/points.png', url: '/dj/points/points', enable: false },
	{ title: '退款列表', img: '../../static/payreturn.png', url: '/dj/payreturn/payreturn', enable: false },
	{ title: '店铺切换', img: '../../static/mops.png', url: '/dj/mchList/mchList', enable: false }
]);
const store = reactive([
	{ title: '个人中心', img: '../../static/myinfo.png', url: '/user/myinfo/myinfo' },
	{ title: '消费记录', img: '../../static/bill.png', url: '/user/bill/bill' },
	{ title: '积分详情', img: '../../static/points.png', url: '/user/points/points' },
	{ title: '退款列表', img: '../../static/payreturn.png', url: '/user/payreturn/payreturn' },
	{ title: '充值活动', img: '../../static/pay.png', url: '/user/pay/pay' },
	{ title: '收货地址', img: '../../static/address.png', url: '/user/address/address' },
	{ title: '商家登录', img: '../../static/mop.png', url: '/pages/store/store' },
	{ title: '用户协议', img: '../../static/xieyi.png', url: '/user/xieyi/xieyi' },
	{ title: '隐私政策', img: '../../static/yinsi.png', url: '/user/yisi/yisi' }
]);
const data = reactive({
	token: get('token') || '',
	user: { avatarUrl: '', name: '', points: '', id: '' },
	mch: { logo: '', title: '' },
	rect: ''
});
const use = ref([]);
onLoad(() => {
	data.rect = uni.getMenuButtonBoundingClientRect().top + 'px';
});
onShow(async () => {
	await getusers();
	await Promise.all([getuser(), getmch(), feature()]);
});
async function feature() {
	try {
		const res = await api.feature();
		if (res.respCode === 200) {
			const list = JSON.parse(res.source);
			use.value = list;
			const mops = mop.value;
			list.forEach((es: any) => {
				mops.forEach((v: any) => {
					if (es.feature === v.title) {
						v.enable = es.enable;
					}
				});
			});
			mop.value = mops;
			console.log(mop.value);
			set('mchuse', list);
		}
	} catch (e) {
		err(e);
	}
}
const getusers = async () => {
	try {
		const res = await api.userxx();
		if (res.respCode === 200) {
			const { respCode, source } = await api.getuser();
			if (respCode === 200) {
				const vuser: any = JSON.parse(source);
				data.user = vuser;
				set('user', vuser);
			}
		} else {
			err(res.msg);
		}
	} catch (error) {
		err(error);
	}
};
const getuser = async () => {
	try {
		const { respCode, source } = await api.getuser();
		if (respCode === 200) {
			const user = JSON.parse(source);
			data.user = user;
			set('user', user);
		}
	} catch (error) {
		err(error);
	}
};
async function getmch() {
	try {
		const id = get('mchId');
		const { respCode, source } = await api.getmch({ id });
		if (respCode === 200) {
			const mch = JSON.parse(source);
			console.log(mch);
			data.mch = mch;
			set('mch', mch);
		}
	} catch (error) {
		err(error);
		throw error;
	}
}
function shop() {
	uni.removeStorageSync('token');
	data.token = '';
}
</script>

<style scoped src="./my.scss"></style>
